<template>
	<view>
		<view class="top-box" :style="'height:'+navHeight+'rpx;'">
			<view class="search-view" style="bottom: 80rpx;">
				<text class="icon fanhui" @click="goBack"></text>
				<picker @change="searchTypeChange" :value="searchType" :range="searchTypes">
					<view class="picker">{{searchTypes[searchType]}}</view>
				</picker>
				<input class="ser-input" confirm-type="search" :value="keyword" @confirm="search" placeholder="快速搜索商标名" />
			</view>
			<view class="navbar">
				<view class="nav-item" :class="{current: cate > 0}">
					<picker @change="cateChange" :value="cate" :range="cates">
						<view class="picker">{{cates[cate]}}</view>
					</picker>
				</view>
				<view class="nav-item" :class="{current: statu > 0}">
					<picker @change="statuChange" :value="statu" :range="status">
						<view class="picker">{{status[statu]}}</view>
					</picker>
				</view>
			</view>
		</view>
		<view class="search-list" :style="'margin-top:'+navHeight+'rpx;'">
			<block v-if="list.length > 0">
				<view v-for="(item, index) in list" :key="index" class="search-item">
					<view class="pic" @click="goDetail(item.number)">
						<image :src="item.pic" mode="aspectFit" lazy-load="true" @error="$imageError(item)"></image>
					</view>
					<view class="status">{{item.status_text}}</view>
					<view class="title" @click="goDetail(item.number)">
						{{item.name}}
					</view>
					<view class="info">
						<view class="number" @click="copyData(item.number)">注册号:{{item.number}}</view>
						<view class="bigcate">{{item.cate}}类</view>
					</view>
				</view>
			</block>
			<view v-else class="empty"><view class="icon hezi"></view><view>暂无数据</view></view>
		</view>
		<view class="gotop">
			<button class="gotop-btn" @click="goTop"><text class="icon xiangshang"></text></button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				navHeight : 0,
				searchTypes : ['近似','注册号','申请人','机构'],
				searchType : 0,
				cates : [],
				cate : 0,
				status : [],
				statu : 0,
				keyword : '',
				list: [],
				page: 1
			}
		},
		onLoad(e){
			let that = this
			uni.getSystemInfo({
			    success: function (res) {
					that.navHeight = res.statusBarHeight * (750 / res.windowWidth) + 160
			    }
			})
			this.searchType = e.searchType ? e.searchType : 0
			this.keyword = e.keyword
			this.page = 1
			if(this.keyword){
				this.loadData('refresh')
			}
		},
		onShow(){
			this.list = uni.getStorageSync('list')
		},
		//加载更多
		onReachBottom(){
			let hasMore = uni.getStorageSync('hasMore')
			if(hasMore){
				this.page++
				this.loadData()
			}
		},
		methods: {
			goDetail(number){
				this.$goto('/pages/search/detail?number='+number)
			},
			copyData(data){
				uni.setClipboardData({
				    data: data,
				    success: function () {
						uni.showToast({
							title: '注册号复制成功',
							icon: 'none',
							duration: 3000
						})
				    }
				})
			},
			goBack(){
				let current = getCurrentPages()
				if(current.length > 1){
					uni.navigateBack()
				}else{
					uni.reLaunch({url: '/pages/index'})
				}
			},
			searchTypeChange(e) {
				this.searchType = e.target.value
			},
			cateChange(e) {
				this.cate = e.target.value
				this.page = 1
				this.goTop()
				this.loadData()
			},
			statuChange(e) {
				this.statu = e.target.value
				this.page = 1
				this.goTop()
				this.loadData()
			},
			search(e){
				this.keyword = e.detail.value
				if(this.keyword){
					this.statu = 0
					this.cate = 0
					this.page = 1
					this.goTop()
					this.loadData()
				}else{
					uni.showModal({
						title: '提示',
						content: '请输入关键词!',
						showCancel : false
					})
				}
			},
			loadData(){
				uni.navigateTo({url: '/pages/common/load?keyword='+this.keyword+'&type='+this.searchType+'&cate='+this.cate+'&statu='+this.statu+'&page='+this.page})
			},
			goTop() {
				uni.pageScrollTo({
					scrollTop: 0,
					duration: 0
				})
			}
		}
	}
</script>

<style lang="scss">
	.top-box{
		.search-view{
			.fanhui{
				font-weight: bold;
				text-align: center;
				width: 60rpx;
				height: 60rpx;
				font-size: 42rpx;
				line-height: 60rpx;
			}
			.picker {
				position: absolute;
				width: 130rpx;
				height: 60rpx;
				font-size: 28rpx;
				line-height: 60rpx;
				text-align: center;
				color: #fff;
				background: $uni-color-primary;
				border-radius:25rpx 0 0 25rpx;
				z-index: 2;
				&:after{
					padding-left: 10upx;
					content: '▾';
				}
			}
			.ser-input{
				padding-left: 140rpx;
			}
		}
		.navbar{
			position: absolute;
			bottom: 0rpx;
			display: flex;
			width: 100%;
			height: 80rpx;
			background: #fff;
			box-shadow: 0 2rpx 10rpx rgba(0,0,0,.06);
			.nav-item{
				flex: 1;
				display: flex;
				justify-content: center;
				align-items: center;
				height: 100%;
				font-size: 30rpx;
				color: #666;
				position: relative;
				&:after{
					padding-left: 15rpx;
					content: '▾';
				}
				&.current{
					color: $uni-color-primary;
					&:after{
						content: '';
						position: absolute;
						left: 50%;
						bottom: 0;
						transform: translateX(-50%);
						width: 80%;
						height: 0;
						border-bottom: 5rpx solid $uni-color-primary;
					}
				}
			}
		}
	}
	.search-list{
		display:flex;
		flex-wrap:wrap;
		height: 100%;
		.search-item{
			position: relative;
			background: #fff;
			float: left;
			width: 46%;
			padding: 1%;
			margin: 1%;
			border-radius: 10upx;
		}
		.pic{
			width: 100%;
			height: 230upx;
			border-radius: 3px;
			overflow: hidden;
			image{
				width: 100%;
				height: 100%;
				opacity: 1;
			}
		}
		.title{
			margin:8upx 0;
			font-size: $font-sm+4upx;
			color: #333;
			letter-spacing: 0;
			display: -webkit-box;
			overflow: hidden;
			text-overflow: ellipsis;
			word-wrap: break-word;
			white-space: normal!important;
			-webkit-line-clamp: 1;
			-webkit-box-orient: vertical;
		}
		.info{
			margin:8upx 5upx;
			display: flex;
			align-items: center;
			justify-content: space-between;
		}
		.number{
			font-size: $font-sm;
			color: $uni-color-primary;
			line-height: 1;
		}
		.status {
			height: 40upx;
			line-height: 40upx;
			text-align: center;
			font-size: $font-sm;
			background: #999;
			color: #fff;
		}
	}
</style>
